<?php
/**
 * 分支升级执行
 */
$_branch_install_sql = "	
CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_batch` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `red_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包id',
        `create_count` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '生成红包的批数（没生成一次减去一次）',
        `already_create_count` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '已经生成的批量数',
        `last_count` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '最后一次生成红包的数量',
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '每次生成的金额',
        `last_money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '最后一次生成的金额',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_cash` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '提现',
        `order_id` CHAR ( 15 ) NOT NULL COMMENT '提现订单id',
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '提现金额',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '提现状态（0=提现中，1=提现成功，2=拒绝提现，9=删除）',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '提现时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_install` ( `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '模块安装时间' ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_media` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0',
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `type` CHAR ( 10 ) NOT NULL COMMENT '文件类型(image=图片，video=视频)',
        `filename` VARCHAR ( 100 ) NOT NULL COMMENT '文件名字',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '上传时间',
        `status` INT ( 1 ) UNSIGNED NOT NULL DEFAULT '2' COMMENT '状态（1=正常，2=审核中）',
        `size` INT ( 10 ) UNSIGNED NOT NULL COMMENT '文件大小',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_media_pic` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `media_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '素材库id',
        `source` VARCHAR ( 255 ) NOT NULL COMMENT '原图',
        `thumb` VARCHAR ( 255 ) NOT NULL COMMENT '缩略图',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_media_video` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `media_id` INT ( 10 ) UNSIGNED NOT NULL,
        `source` VARCHAR ( 255 ) NOT NULL COMMENT '视频地址',
        `thumb` VARCHAR ( 255 ) NOT NULL COMMENT '视频封面地址',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_member` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `phone` CHAR ( 11 ) NOT NULL COMMENT '用户手机号码',
        `balance` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '用户余额',
        `register_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '注册时间',
        `hint_more` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '是否提示上拉加载更多',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_order` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0',
        `uid` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0',
        `order_id` CHAR ( 15 ) NOT NULL COMMENT '订单id',
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '订单金额',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '订单状态（1=未支付，2=支付成功，9=删除）',
        `source` CHAR ( 10 ) NOT NULL COMMENT '支付来源(red=发红包)',
        `source_id` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '资源的响应id,红包id,其他id',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_person_publish` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态（1=正常，0=审核，9=删除）',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '申请时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_question` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `red_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包id',
        `question` VARCHAR ( 50 ) NOT NULL COMMENT '问题',
        `options` text,
        `answer` CHAR ( 20 ) NOT NULL COMMENT '答案下标||答案',
        PRIMARY KEY ( `id` ),
    KEY `red_id` ( `red_id` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_record` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户id(手气红包未开启=0)',
        `red_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包id',
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '红包金额',
        `time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '开红包时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_red` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '红包',
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0',
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '红包金额（普通红包=单个红包，拼手气红包等于红包总额）',
        `type` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '红包类型（1=拼手气，2=普通红包）',
        `number` MEDIUMINT ( 7 ) UNSIGNED NOT NULL COMMENT '红包数量',
        `already_number` MEDIUMINT ( 7 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '红包已发数量',
        `title` VARCHAR ( 30 ) NOT NULL COMMENT '红包标题',
        `cover` VARCHAR ( 255 ) DEFAULT '' COMMENT '红包封面',
        `share` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '是否支持转发开红包（1=支持，0=不支持）',
        `charge` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '手续费',
        `pay` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '需要支付',
        `red_type` CHAR ( 10 ) NOT NULL DEFAULT '' COMMENT '红包类型（normal=默认、pic=图片红包、video=视频红包）',
        `media` text NOT NULL COMMENT '相关素材（pic、vedio、slide）',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '红包状态（1=等待支付发红包，2=正常发布中，3=红包已发完，4=停止发红包，9=删除）',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包发放时间',
        `open_check` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否开启开红包问题验证（0=不开启，1=选择题，2=问答题）',
        `area_type` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '可开红包地区（0=不限制，1=省，2=市，3=区）',
        `area` VARCHAR ( 100 ) DEFAULT NULL COMMENT '开红包的限制地区（省/市/区）',
        `link_id` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户的推广链接id',
        `coerce_phone` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否强制用户完成手机号认证（1=强制，0=不强制）',
        PRIMARY KEY ( `id` ),
        KEY `uniacid` ( `uniacid` ) USING BTREE,
    KEY `uid` ( `uid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_refund` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `order_id` CHAR ( 15 ) NOT NULL COMMENT '退款订单号',
        `pay_order_id` CHAR ( 15 ) NOT NULL COMMENT '支付订单号',
        `money` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL COMMENT '退款金额',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '退款时间',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态（0=处理中，1=退款成功，2=退款失败）',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_setting` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0',
        `web_name` CHAR ( 10 ) DEFAULT NULL COMMENT '网站名称',
        `user_media_size` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '10' COMMENT '用户素材库初始大小（单位M）',
        `media_check` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '2' COMMENT '是否审核素材库内容（1=不审核，2=审核）',
        `image_limit_size` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '单个图片上传大小限制',
        `video_limit_duration` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '60' COMMENT '视频限制时长',
        `publish_red` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '发红包功能是否对外开放（0=不对外开放、1=对外开放）',
        `normal_red_ratio` DOUBLE ( 4, 3 ) UNSIGNED NOT NULL DEFAULT '0.001' COMMENT '普通红包手续费比例',
        `pic_red_ratio` DOUBLE ( 4, 3 ) NOT NULL DEFAULT '0.001' COMMENT '图片红包手续费比例',
        `video_red_ratio` DECIMAL ( 4, 3 ) UNSIGNED NOT NULL DEFAULT '0.001' COMMENT '视频发红包收费比率',
        `lowest_cash` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL DEFAULT '1.00' COMMENT '用户最低提现金额',
        `auto_cash` DECIMAL ( 10, 2 ) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '自动到账金额限制（金额不大于多少可自动提现）',
        `cash_remark` VARCHAR ( 255 ) DEFAULT NULL COMMENT '提现成功时微信提示的信息',
        `defend` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否开启酷源防封',
        `attention` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '前台是否显示关注信息（0=不显示，1=显示）',
        `attention_publish` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '发布是否提示用户关注公众号1',
        `map_key` CHAR ( 32 ) DEFAULT NULL COMMENT '高德地图Key',
        `message_media_check` VARCHAR ( 50 ) DEFAULT NULL COMMENT '素材库上传审核通知管理员模板消息ID',
        `message_media_pass` VARCHAR ( 50 ) DEFAULT NULL COMMENT '素材审核通过通知模板消息ID',
        `admin_uid` INT ( 10 ) UNSIGNED DEFAULT '0' COMMENT '管理员uid',
        `notice` VARCHAR ( 255 ) DEFAULT NULL COMMENT '公告内容',
        `notice_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '公告修改时间',
        `use_balance` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '余额使用微擎通用余额或者模块独立余额',
        `open_phone` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否开启用户手机认证功能（1=开启，0=不开启）',
        `coerce_phone` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否强制用户认证手机号码后领取红包（1=强制，0=不强制）',
        PRIMARY KEY ( `id` ),
    KEY `uniacid` ( `uniacid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_cloud` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `wx_appid` VARCHAR ( 50 ) NOT NULL COMMENT '公众号appid',
        `identity` CHAR ( 10 ) NOT NULL COMMENT '云服务唯一注册码',
        `module` VARCHAR ( 20 ) NOT NULL COMMENT '模块标识',
        `authority` CHAR ( 40 ) DEFAULT '' COMMENT '授权码',
        `past_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '授权码过期时间',
        `check_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '客户端验证时间',
        `register_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '云服务注册时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8 ROW_FORMAT = COMPACT;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_multi_sync` ( `id` TINYINT ( 1 ) UNSIGNED NOT NULL AUTO_INCREMENT, `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '公众号id', PRIMARY KEY ( `id` ) ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_read_notice` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '阅读时间（与修改公告时间对比，一样则已读）',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_link` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `name` CHAR ( 8 ) NOT NULL COMMENT '链接名字',
        `link` VARCHAR ( 255 ) NOT NULL COMMENT '链接地址',
        PRIMARY KEY ( `id` ),
        KEY `uniacid` ( `uniacid` ) USING BTREE,
    KEY `uid` ( `uid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_red_share_id` (
        `id` CHAR ( 8 ) NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT 'uid',
        `red_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '红包id',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
";
pdo_run($_branch_install_sql);


/**
 * 1.0.1
 * 删除微信商户相关信息字段
 */
if(pdo_fieldexists('kuyuan_red_setting','wx_key')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." DROP COLUMN `wx_key`;");
}
if(pdo_fieldexists('kuyuan_red_setting','wx_account')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." DROP COLUMN `wx_account`;");
}
if(pdo_fieldexists('kuyuan_red_setting','wx_secret')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." DROP COLUMN `wx_secret`;");
}
if(pdo_fieldexists('kuyuan_red_setting','wx_appid')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." DROP COLUMN `wx_appid`;");
}

/**
 * 1.0.3
 * 参数表新增参数（关注attention）
 */
if(!pdo_fieldexists('kuyuan_red_setting','attention')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `attention` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_red_setting','attention_publish')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `attention_publish` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}

/**
 * 1.0.4
 * 红包表 kuyuan_red_red
 *  新增可开红包地区限制类型  area_type
 *  新增红包地区限制  area
 *基础设置表 kuyuan_red_setting
 *  新增高德地图Key map_key
 *  素材库上传通知管理员审核 message_media_check
 *  素材库审核结果通知用户 message_media_pass
 *  系统管理员uid admin_uid
 *  系统公告 notice
 *  系统公告修改时间 notice_time
 *新建公告阅读记录表 kuyuan_red_read_notice
 */
if(!pdo_fieldexists('kuyuan_red_red','area_type')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_red')." ADD COLUMN `area_type` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_red_red','area')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_red')." ADD COLUMN `area` varchar(100) NULL;");
}

if(!pdo_fieldexists('kuyuan_red_setting','map_key')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `map_key` char(32) NULL;");
}
if(!pdo_fieldexists('kuyuan_red_setting','message_media_check')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `message_media_check` varchar(50) NULL;");
}
if(!pdo_fieldexists('kuyuan_red_setting','message_media_pass')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `message_media_pass` varchar(50) NULL;");
}
if(!pdo_fieldexists('kuyuan_red_setting','admin_uid')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `admin_uid` int(10) UNSIGNED NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_red_setting','notice')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `notice` varchar(255) NULL;");
}
if(!pdo_fieldexists('kuyuan_red_setting','notice_time')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `notice_time` int(10) UNSIGNED NOT NULL DEFAULT 1;");
}

/**
 * 1.0.5
 * 红包问答表 kuyuan_red_question
 *  更改答案字段类型  answer
 *  新增表索引 red_id
 *  选择题选项 options 可以是null
 */
if(pdo_fieldmatch("kuyuan_red_question","answer","char") <= 0){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_question')." MODIFY COLUMN `answer` char(20) NOT NULL;");
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_question')." MODIFY COLUMN `options` text NULL;");
}
if(!pdo_indexexists("kuyuan_red_question","red_id")){
    pdo_query("CREATE INDEX `red_id` ON ".tablename('kuyuan_red_question')." (`red_id` ASC) USING BTREE;");
}

/**
 * 1.1.4
 * 配置表 kuyuan_red_setting
 *      新增use_balance  系统使用微擎官方余额或者模块独立余额
 *      新增索引 uniacid
 */
if(!pdo_fieldexists('kuyuan_red_setting','use_balance')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `use_balance` tinyint(1) UNSIGNED NOT NULL DEFAULT 1;");
}
if(!pdo_indexexists("kuyuan_red_setting","uniacid")){
    pdo_query("CREATE INDEX `uniacid` ON ".tablename('kuyuan_red_question')." (`uniacid` ASC) USING BTREE;");
}

/**
 * 1.1.5
 * 红包表 ims_kuyuan_red_red
 *      新增 推广链接id link_id
 *      新增索引 uniacid
 *      新增索引 uid
 */
if(!pdo_fieldexists('kuyuan_red_red','link_id')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_red')." ADD COLUMN `link_id` int(10) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_indexexists("kuyuan_red_red","uniacid")){
    pdo_query("CREATE INDEX `uniacid` ON ".tablename('kuyuan_red_red')." (`uniacid` ASC) USING BTREE;");
}
if(!pdo_indexexists("kuyuan_red_red","uid")){
    pdo_query("CREATE INDEX `uid` ON ".tablename('kuyuan_red_red')." (`uid` ASC) USING BTREE;");
}

/**
 * 1.2.5
 * 参数表 red_setting
 *      新增 手机认证功能开关 open_phone
 *      新增  强制用户完善认证手机开关 coerce_phone
 * 会员表 red_member
 *      新增 用户手机字段 phone
 * 红包表 red_red
 *      新增 强制用户完善认证手机 coerce_phone
 */
if(!pdo_fieldexists('kuyuan_red_setting','coerce_phone')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `coerce_phone` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_red_setting','open_phone')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_setting')." ADD COLUMN `open_phone` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}
if(!pdo_fieldexists('kuyuan_red_member','phone')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_member')." ADD COLUMN `phone` char(11) NOT NULL;");
}
if(!pdo_fieldexists('kuyuan_red_red','coerce_phone')){
    pdo_query("ALTER TABLE ".tablename('kuyuan_red_red')." ADD COLUMN `coerce_phone` tinyint(1) UNSIGNED NOT NULL DEFAULT 0;");
}